<?php
/**
 * Desc:
 * User: aniu
 * Date: 2021/1/2
 * Time: 下午12:53
 * @return
 */

namespace App\Http\Controller;

use App\Http\Bean\TestBean;
use Swoft\Bean\Annotation\Mapping\Inject;
use Swoft\Http\Message\Response;
use Swoft\Http\Server\Annotation\Mapping\Controller;
use Swoft\Http\Server\Annotation\Mapping\RequestMapping;
use Toolkit\Cli\App;

/**
 * @Controller("test")
 * Desc:
 * User: aniu
 * Date: 2021/1/2
 * Time: 下午1:44
 * ${PARAM_DOC}
 * @return ${TYPE_HINT}
 * ${THROWS_DOC}
 */
class TestController
{
    /**
     * @RequestMapping("bean")
     * Desc:
     * User: aniu
     * Date: 2021/1/2
     * Time: 下午1:44
     */
    public function Bean()
    {
        $test = \Swoft::getBean(TestBean::class);
        $test->setName('aniu');
        return $test->getName();
    }


    /**
     * @Inject()
     * @var TestBean
     */
    private $test;

    /**
     * @RequestMapping("index/{age}")
     * @return string
     * Desc:
     * User: aniu
     * Date: 2021/1/2
     * Time: 下午2:26
     */
    public function index(int $age)
    {
        $name = $this->test->getName();
        return "My name is ".$name." age is ".$age;
    }


    /**
     * @RequestMapping("/listen")
     * Desc:
     * User: aniu
     * Date: 2021/1/2
     * Time: 下午3:06
     */
    public function testListener(Response $response)
    {
        \Swoft::trigger("aniu", null, 'test','listen');
        return $response->withData(array(['code'=>'test']));
    }
}

